package com.taurus.myboard.utils;

import org.springframework.stereotype.Service;

import java.io.*;

@Service
public class ReadUtils {
    public String ReadFile(String Path){
        BufferedReader reader = null;  //BufferedReader:入参有Reader对象和缓冲区大小（可不写）从缓冲区读取字符流，提高效率；缓冲区大小：默认8192，默认不需要传递建议都要用这个类去读取文件
        String laststr = "";
        try{
            FileInputStream fileInputStream = new FileInputStream(Path);
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
            reader = new BufferedReader(inputStreamReader);
            String tempString = null;
            while((tempString = reader.readLine()) != null){   //BufferedReader对象使用readLine()方法判断字符串是否为null判断是否为文件末尾
                laststr += tempString;
            }
            reader.close();
        }catch(IOException e){
            e.printStackTrace();
        }finally{
            if(reader != null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return laststr;
    }
}
